package com.eric.controller;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.util.SaResult;
import cn.hutool.core.bean.BeanUtil;
import com.eric.domain.bso.PermissionBso;
import com.eric.domain.dto.SysPermissionDto;
import com.eric.domain.po.SysPermission;
import com.eric.service.ISysPermissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-03-12
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sys-permission")
public class SysPermissionController {
    private final ISysPermissionService sysPermissionService;
    @PostMapping("/savePermissionList")
    @SaCheckRole(value = {"sys:coder"},mode = SaMode.OR)
    public SaResult savePermissionList(@RequestBody List<SysPermissionDto>permissionDtos){
        return sysPermissionService.savePermissionListService(permissionDtos);
    }

    @GetMapping("/getAllPermissions")
    public SaResult getPermissions(){
        return sysPermissionService.getAllPermissions();
    }
    @PutMapping("/modifyOne")
    @SaCheckRole(value = {"sys:coder"},mode = SaMode.OR)
    public SaResult modifyOne(@RequestBody SysPermissionDto permissionDto){
        return sysPermissionService.modifyOneService(permissionDto);
    }

    @GetMapping("/getByName")
    public SaResult getByName(String name,Integer current,Integer pageSize){
        return sysPermissionService.getByNameService(name,current,pageSize);
    }

//   获取所有的权限列表
    @GetMapping("/getAll")
    public SaResult getAllPermissions(){
        List<SysPermission> permissionList = sysPermissionService.list();
        List<PermissionBso> permissionBsoList = BeanUtil.copyToList(permissionList, PermissionBso.class);
        return SaResult.data(permissionBsoList);
    }


}
